<template>
    <div>
        <form action="/">
            <van-search v-model="searchval" show-action placeholder="请输入搜索关键词" @search="onSearch"
                @cancel="() => { router.push('/home/index') }" />
        </form>
        <div v-for="item in searchdata" > <van-cell-group>
                <van-cell :title="item.goods_name" />
            </van-cell-group>
        </div>
        <van-empty description="描述文字" v-show="his" />
        <div class=" his" v-show="!his">
            <van-cell-group>
                <van-cell icon="search" title="vue" />
                <van-cell icon="search" title="vue" />
                <van-cell icon="search" title="vuexx" />
                <van-cell icon="search" title="vuexx" />
                <van-cell icon="search" title="vuexx" />
                <van-cell icon="search" title="vue和vue3" />
                <van-cell icon="search" title="vue和vue3" />
                <van-cell icon="search" title="vue和vue3" />
                <van-cell icon="search" title="vue和vue3" />

            </van-cell-group>
        </div>
    </div>
</template>

<script setup>
import { useRouter } from 'vue-router';
const router = useRouter()
import { qsearchApi } from '@/api/api'
import { ref, watch } from 'vue';
const searchval = ref('')
const his = ref('')
const lb = ref('')
const searchdata = ref([])
watch(searchval, (val) => {
    // if (searchval.length = 0) {
    //     his.value = false
    // } else {
        qsearchApi(val).then(res => {
            console.log(res);
            searchdata.value = res.data.message
            // if (res.data.message.length = 0) {
            //     his.value = true
            //     lb.value = false
            // } else {
            //     lb.value = true

            // }
        })
    // }

})
</script>

<style lang="scss" scoped></style>